<?php

class Office_modul  extends CI_Model {
    public $select;

    public function __construct() {
        // Call the Model constructor
        parent::__construct();
    }

 
 
    /**
     * Поиск наглавной главная
     *
     * @return void
     * @author
     */

    public function request($id=0) {

        $this -> load -> helper('see');
        
        $data = false;
        $select_data = array();
        $DB2 = $this -> load -> database('adsent', TRUE, TRUE);

   echo $select = "SELECT   
      a.id a_id,
      a.region_id a_region_id ,
      a.region_names  a_region_names , 
      a.city_id a_city_id ,
      a.city_name a_city_name , 
      a.street_id , 
      a.street_name ,
      a.id_adsent , 
      a.contact_telefon1 ,
      a.contact_name1 ,
      a.contact_telefon2 ,
      a.contact_name2 ,
      a.points , 
      a.name_type , 
      a.id_phone , 
      a.datetime ,
      a.active ,
      
      
    r.id,  
    r.area,
    r.object_type ,
    r.adress_name,
    r.region_names,
    r.region_id,
    r.city_name,
    r.city_id,
    r.street_name,
    r.street_id,
    r.home_id, 
    r.price,
    r.currency,   
    r.floor,  
    r.floorn,
    
    r.t_area,
    
    r.contract,
    r.building,
    r.enter,
          
     
    r.comment_client,
    r.comment_site,
    r.keepday, 
    
    
    r.contact_telefon1,
    r.contact_name1,
    r.contact_telefon2,
    r.contact_name2,
    r.id_phone,
    r.act,
    r.datetime,
    r.moderator,
    
    
    m.id m_id,
    m.name m_name,
    i.name i_name
    
   FROM `adsent` AS `a`     join `soffice` `r` ON r.id = a.id_adsent AND a.name_type ='soffice' 
 
 
  left join `img` `i` ON i.adsent = r.id and i.type = 'soffice' 
  
  
     left join `metro` `m` ON m.id = r.id_metro   
    where r.id = $id ;";
    
        $q = $DB2 -> query($select);

        if ($q -> num_rows() > 0) {

            foreach ($q -> result() as $row) {
 
                 $data[] = 
                        array('a_id' => $row -> a_id, 'a_region_id' => $row -> a_region_id, 'a_region_names' => $row -> a_region_names, 
                        'a_city_id' => $row -> a_city_id, 'a_city_name' => $row -> a_city_name, 'a_street_id' => $row -> street_id, 'a_street_name' => $row -> street_name, 
                        'a_id_adsent' => $row -> id_adsent, 'a_contact_telefon1' => $row -> contact_telefon1, 'a_contact_name1' => $row -> contact_name1, 
                        'a_contact_telefon2' => $row -> contact_telefon2, 'a_contact_name2' => $row -> contact_name2, 'a_points' => $row -> points,
                         'a_name_type' => $row -> name_type, 'a_id_phone' => $row -> id_phone, 'a_datetime' => $row -> datetime, 'a_active' => $row -> active, 
                         'id' => $row -> id, 'root' => sale_object_type($row -> object_type), 'contract' => sale_contract_object_type($row -> contract), 
                         
                         't_area' => $row -> t_area, 'r_area' => $row -> area, 'r_adress_name' => $row -> adress_name, 'r_region_names' => $row -> region_names,
                          'r_region_id' => $row -> region_id, 'r_city_name' => $row -> city_name, 'r_city_id' => $row -> city_id, 'r_street_name' => $row -> street_name,
                           'r_street_id' => $row -> street_id, 'r_home_id' => $row -> home_id, 'r_price' => $row -> price, 'floor' => $row -> floor, 'floorn' => $row -> floorn, 
                           'building' => sale_contract_office_building($row -> building), 'enter' => sale_contract_office_enter($row -> enter), 'comment_client' => $row -> comment_client, 
                           'r_comment_site' => $row -> comment_site, 'r_keepday' => $row -> keepday, 'contact_telefon1' => $row -> contact_telefon1, 'contact_name1' => $row -> contact_name1, 
                           'contact_telefon2' => $row -> contact_telefon2, 'contact_name2' => $row -> contact_name2, 'r_id_phone' => $row -> id_phone, 'r_act' => $row -> act, 
                           'r_datetime' => $row -> datetime, 'r_moderator' => $row -> moderator,'m_id'  => $row -> m_id,'m_name'  => $row -> m_name,'i_name'  => $row -> i_name,);
            }
        }

        return $data;
    }

 
 
 
 
/*
 * разбор типа объекта
 * */

 public function metro_distance($value=0)
 {
     switch ($value) {
         case 0:
             $str = 'пешком';
             break;
         
         case 1:
             $str = 'транспортом';
              
             break; 
     }
     
     return $str;
 }
 
 
/*
 * разбор типа объекта
 * */

 public function d_currency($value=0)
 {
     switch ($value) {
         case 0:
             $str = 'пешком';
             break;
         
         case 1:
             $str = 'транспортом';
              
             break; 
     }
     
     return $str;
 }
 
  
 
/*
 * типа аренды по времени
 * */

 public function for_days($value=0)
 {
     switch ($value) { 
         case 1:
             $str = 'от месяца и более<br> (длительный срок <br>или сезонная сдача)';
              
             break; 
         case 2:
             $str = 'посуточная аренда';
              
             break; 
         case 3:
             $str = 'только сезонная сдача<br> (на несколько месяцев)';
              
             break; 
         case 4:
             $str = 'только длительный<br> срок аренды <br>(от года и более)';
              
             break; 
         default:
             $str = 'любой срок аренды';
          break; 
     }
     
     return $str;
 }
 
   
   

}
